#include <iostream>
#include <string>

using namespace std;

bool canConstruct(string ransomNote, string magazine) {
    // int countArray[26] {};
    // for (int i = 0, len = static_cast<int>(magazine.length()); i < len; i++) {
    //     countArray[static_cast<int>(magazine.at(i) - 'a')]++;
    // }

    // for (int i = 0, len = static_cast<int>(ransomNote.length()); i < len; i++) {
    //     int count = --countArray[static_cast<int>(ransomNote.at(i) - 'a')];
    //     if (count < 0) {
    //         return false;
    //     }
    // }

    // return true;

    // 排除长度不符合的情况，不使用 static_cast 进行类型转化
    if (ransomNote.length() > magazine.length()) {
        return false;
    }
    
    int countArray[26] {};
    for (int i = 0, len = magazine.length(); i < len; i++) {
        countArray[magazine[i] - 'a']++;
    }

    for (int i = 0, len = ransomNote.length(); i < len; i++) {
        int count = --countArray[ransomNote.at(i) - 'a'];
        if (count < 0) {
            return false;
        }
    }

    return true;
}

int main() {
    string ransomNote { "aa" }, magazine { "aab" };

    cout << boolalpha;
    cout << canConstruct(ransomNote, magazine) << "\n";

    return 0;
}